package com.atguigu.eduservice.controller.frontController;

import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.service.EduCourseService;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sun.xml.internal.messaging.saaj.soap.impl.CDATAImpl;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ReactiveRedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author cyt
 * @create 2020-05-16 9:36
 */


@Api(description = "前台讲师")
@RestController
@RequestMapping("/eduservice/frontTeacher")

public class TeacherFrontController {
    @Autowired
    EduCourseService eduCourseService;
    @Autowired
    EduTeacherService eduTeacherService;

    // 前台讲师分页
    @GetMapping("/getTeacherList/{page}/{limit}")
    public R getTeacherList(@PathVariable("page") String page, @PathVariable("limit") String limit) {
        Page<EduTeacher> eduTeacherpage = new Page<EduTeacher>(Integer.parseInt(page), Integer.parseInt(limit));

        Map<String, Object> map = eduTeacherService.getTeacherList(eduTeacherpage);

        return R.ok().data(map);
    }

    // 讲师详情、课程信息
    @GetMapping("/TeacherInfo/{teacherId}")
    public R TeacherInfo(@PathVariable("teacherId") String teacherId) {
        // 查出老师
        EduTeacher teacher = eduTeacherService.getById(teacherId);
        // 查出课程
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id", teacherId);
        List<EduCourse> list = eduCourseService.list(wrapper);
        return R.ok().data("teacher", teacher).data("eduCourse", list);
    }


}
